<?php
session_start();
require('../conn.php');
require('../functions.php');
require('admin.php');
$id=guolv($_GET['id']);
$aid=guolv($_POST['id']);
if(is_numeric($id)==false){
		echo "<script>alert('广告不存在');location.href='adlist.php'</script>";
		exit;	
}
$row=$mysql->query("select * from `addata` where `id`='{$id}'");

if($_POST && is_numeric($aid)){
    $ad_type=guolv($_POST['ad_type']);
    $ad_list=guolv($_POST['ad_list']);
    $ad_title=guolv($_POST['ad_title']);
    $ad_thumb=guolv($_POST['ad_thumb']);
    $ad_url=guolv($_POST['ad_url']);
    $ad_profile=guolv($_POST['ad_profile']);
    $ad_pv=guolv($_POST['ad_pv']);
		$endtime=guolv($_POST['ad_endtime']);
		$mysql->execute("update `addata` set `ad_type`='{$ad_type}',`ad_list`='{$ad_list}',`ad_title`='{$ad_title}',`ad_thumb`='{$ad_thumb}',`ad_url`='{$ad_url}',`ad_profile`='{$ad_profile}',`pv`='{$ad_pv}',`endtime`='{$endtime}' where `id`='{$aid}'");
		echo "<script>alert('修改成功');location.href='edit_ad.php?id={$aid}'</script>";
		exit;
}
?>

<?php include('head.php')?>   
<link rel="stylesheet" href="../editor/themes/default/default.css" />
  <link rel="stylesheet" href="../editor/plugins/code/prettify.css" />
  <script src="static/jquery.js" type="text/javascript"></script> 
  <script charset="utf-8" src="../editor/kindeditor.js"></script>
  <script charset="utf-8" src="../editor/lang/zh_CN.js"></script>
  <script charset="utf-8" src="../editor/plugins/code/prettify.js"></script>
  <script>
    KindEditor.ready(function(K) {
      var editor1 = K.create('textarea[name="content"]', {
        cssPath : '../editor/plugins/code/prettify.css',
        uploadJson : '../editor/php/upload_json.php',
        fileManagerJson : '../editor/php/file_manager_json.php',
        allowFileManager : true,
        filterMode: false,//是否开启过滤模式
      });
      prettyPrint();
    });
  </script>
<script>
      KindEditor.ready(function(K) {
        var uploadbutton = K.uploadbutton({
          button : K('#uploadButton')[0],
          fieldName : 'imgFile',
          url : '../editor/php/upload_json.php?dir=image',
          afterUpload : function(data) {
            if (data.error === 0) {
              var url = K.formatUrl(data.url, 'absolute');
              K('#img').val(url);
                            $.post("../editor/php/dunling.php",{
                            url:url
                            },function(slta,sltb){
                            //****//
                            });
            } else {
              alert(data.message);
            }
          },
          afterError : function(str) {
            alert('自定义错误信息: ' + str);
          }
        });
        uploadbutton.fileBox.change(function(e) {
          uploadbutton.submit();
        });
      });
</script>  
    <div class="container-fluid">
        
        <div class="row-fluid">
		<?php
		include('left.php');
		?>
<div class="span9">
            <h1 class="page-title">广告管理</h1>
<!--			
<div class="btn-toolbar">
    <a href="#myModal" data-toggle="modal" class="btn">Delete</a>
  <div class="btn-group">
  </div>
</div>
-->
<div class="well">
    <ul class="nav nav-tabs">
      <li class="active"><a href="#home" data-toggle="tab">发布</a></li>
      <!--<li><a href="#profile" data-toggle="tab">图片上传</a></li>-->
    </ul>
    <div id="myTabContent" class="tab-content">
      <div class="tab-pane active in" id="home">	  
    <form id="tab" action="edit_ad.php?id=<?php echo $id?>" method="post">
		<input type="hidden" name="id" value="<?php echo $id?>">
		<!-- <label><?php echo $row[0]['ad_type']?></label> -->
        <!--<input type="text" value="" style="width:500px" name="pic">
		<input name="filename" type="file">-->    
    <!-- <input type="hidden" name="do" value="ad"> -->
    <label>广告类型：- <?php echo $row[0]['ad_type']?> </label>
    <select name="ad_type">
      <option value="底部广告">底部广告</option>
      <option value="顶部广告">顶部广告</option>
    </select>
    <label>投放区域：- <?php echo $row[0]['ad_list']?></label>
      <select name="ad_list">
          <option value="0全站投放" selected>全站投放</option>
      </select>   
    
    <label>标题：</label>
    <input type="text" value="<?php echo $row[0]['ad_title']?>" style="width:200px" name="ad_title">

    <label>缩略图：</label>
    <input style="width: 250px;" type="text" id="img" value="<?php echo $row[0]['ad_thumb']?>" name="ad_thumb"/>
    <input type="button" id="uploadButton"  class="ke-default-input" value="选择图片"/>

    <label>链接：</label>
    <input type="text" value="<?php echo $row[0]['ad_url']?>" style="width:200px" name="ad_url">

    <label>广告简介：</label>
    <input type="text" value="<?php echo $row[0]['ad_profile']?>" style="width:200px" name="ad_profile">

    <label>点击次数：</label>
    <input type="text" value="<?php echo $row[0]['pv']?>" style="width:200px" name="ad_pv">

    
    <label>到期时间：</label>
    <input class="datepicker" type="text" value="<?php echo $row[0]['endtime']?>" style="width:200px" name="ad_endtime">   
		<!-- <label></label>		 -->
		<!-- <textarea value="Smith" rows="10" name="ad_content" style="width:800px;height:400px;"><?php echo $row[0]['ad_content']?></textarea> -->
		 <!-- <label></label> -->
     <hr>
		 <button class="btn btn-primary"><i class="icon-save"></i> 保存</button>
    </form>
      </div>
      <div class="tab-pane fade" id="profile">
    <form id="tab2">
        <label>New Password</label>
        <input type="password" class="input-xlarge">
        <div>
            <button class="btn btn-primary">Update</button>
        </div>
    </form>
      </div>
  </div>

</div>

<div class="modal small hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Delete Confirmation</h3>
  </div>
  <div class="modal-body">
    
    <p class="error-text"><i class="icon-warning-sign modal-icon"></i>Are you sure you want to delete the user?</p>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
    <button class="btn btn-danger" data-dismiss="modal">Delete</button>
  </div>
</div>

        </div>
    </div>
    

    
    <footer>
        <hr>
        
        <p class="pull-right"><!--power by right--></p>
        
        
        <p><!--power by --></p>
    </footer>
    

    

    <!-- Le javascript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
	<script src="lib/bootstrap/js/bootstrap.js"></script>
  <script type="text/javascript" src="../static/jquery.js"></script>
  <script type="text/javascript" src="../static/jquery.datePicker-min.js"></script>
  <link type="text/css" href="../static/datetime.css" rel="stylesheet" />
  <script type="text/javascript">
  $(document).ready(function(){
    $(".datepicker").datePicker({
      clickInput:true
    });
  });
  </script>  


  </body>
</html>


